import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const List = []
const count = 30

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id:'@increment(1, 100)',
    'status|1': _.map(consts.TRANSFER_STATUS, 'value'),
    'accountType|1': _.map(consts.ACCOUNT_TYPE, 'value'),
    time:  +Mock.Random.date('T'),
    updateTime:  +Mock.Random.date('T'),
    orderNo: '@int(1000, 10000, 2, 2)',
    orderNo2: '@int(1000, 10000, 2, 2)',
    account: '@float(0, 100, 2, 2)',
    gameAccount: '@float(0, 100, 2, 2)',
    'from|1':_.map(consts.TRANSFER_PLATFORMS,'value'),
    'to|1':_.map(consts.TRANSFER_PLATFORMS,'value'),
    money: '@int(0, 100, 2, 2)',
    balanceCenter: '@int(0, 100, 2, 2)',
    balancePlatform: '@int(0, 100, 2, 2)',
  }))
}

export default {
  [api.TRANSFER_LIST]: config => {
    const { page, limit } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.TRANSFER_DETAIL]: config => {
    const {id, page = 1, limit = 20 } = param2Obj(config.body)

    const item = _.find(List,o=>o.id == id)


    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail: item
      },
      code: 1,
    };
  },
  [api.TRANSFER_GET_CONFIGS]: config => {
    const configs = {
      toCenter:{
        times: 10,
        min:10,
        max: 1000
      },
      toOthers:{
        times: 10,
        min:10,
        max: 1000
      },
      platforms:[
        {
          id:1,
          label:'中心钱包',
          key:'center',
          value:1,
        },
        {
          id:2,
          label:'AG平台',
          key:'ag',
          value:1,
        },
        {
          id:3,
          label:'PT平台',
          key:'pt',
          value:2,
        },
      ]
    }

    return {
      data: {
        configs: configs
      },
      code: 1,
    };
  },

}
